<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['projectName']" placeholder="请输入项目名称"></a-input>
        </a-form-item>
        <a-form-item label="项目阶段" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['projectStage']" placeholder="请输入项目阶段"></a-input>
        </a-form-item>
        <a-form-item label="项目分类" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['projectClass']" placeholder="请输入项目分类"></a-input>
        </a-form-item>
        <a-form-item label="组别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['teamGroup']" placeholder="请输入组别"></a-input>
        </a-form-item>
        <a-form-item label="组名" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['teamName']" placeholder="请输入组名"></a-input>
        </a-form-item>
        <a-form-item label="投资方" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['investors']" placeholder="请输入投资方"></a-input>
        </a-form-item>
        <a-form-item label="乡镇" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['townName']" placeholder="请输入乡镇"></a-input>
        </a-form-item>
        <a-form-item label="县直单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['deptName']" placeholder="请输入县直单位"></a-input>
        </a-form-item>
        <a-form-item label="归属地" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['beloneto']" placeholder="请输入归属地"></a-input>
        </a-form-item>
        <a-form-item label="内容和规模" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['contents']" placeholder="请输入内容和规模"></a-input>
        </a-form-item>
        <a-form-item label="地区国家" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['area']" placeholder="请输入地区国家"></a-input>
        </a-form-item>
        <a-form-item label="企业属性" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['enterpriseType']" placeholder="请输入企业属性"></a-input>
        </a-form-item>
        <a-form-item label="产业类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['industryType']" placeholder="请输入产业类型"></a-input>
        </a-form-item>
        <a-form-item label="产类具体分类" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['industryClass']" placeholder="请输入产类具体分类"></a-input>
        </a-form-item>
        <a-form-item label="使用方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['useType']" placeholder="请输入使用方式"></a-input>
        </a-form-item>
        <a-form-item label="总额" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['totalAmount']" placeholder="请输入总额" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="内资" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['domesticAmount']" placeholder="请输入内资" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="外资" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['foreignAmount']" placeholder="请输入外资" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="责任人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['responsePerson']" placeholder="请输入责任人"></a-input>
        </a-form-item>
        <a-form-item label="分管领导" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['fgLeader']" placeholder="请输入分管领导"></a-input>
        </a-form-item>
        <a-form-item label="联系人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['contactPerson']" placeholder="请输入联系人"></a-input>
        </a-form-item>
        <a-form-item label="企业联系人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['enterpriseContact']" placeholder="请输入企业联系人"></a-input>
        </a-form-item>
        <a-form-item label="实际个数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['realNum']" placeholder="请输入实际个数" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="实际金额" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['realAmount']" placeholder="请输入实际金额" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="三年计划投资总额" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['threeAmount']" placeholder="请输入三年计划投资总额" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="三年计划内资" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['threeDomestic']" placeholder="请输入三年计划内资" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="三年计划外资" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['threeForeign']" placeholder="请输入三年计划外资" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="文件id" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['fileIds']" placeholder="请输入文件id"></a-input>
        </a-form-item>
        <a-form-item label="备注信息" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['remarks']" placeholder="请输入备注信息"></a-input>
        </a-form-item>
        <a-form-item label="项目年份" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['projectYear']" placeholder="请输入项目年份"></a-input>
        </a-form-item>
        <a-form-item label="审核状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['auditStatue']" placeholder="请输入审核状态" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="是否落地" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['isLd']" placeholder="请输入是否落地"></a-input>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  
  export default {
    name: "ProjectSummaryModal",
    components: { 
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/project/projectSummary/add",
          edit: "/project/projectSummary/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'projectName','projectStage','projectClass','teamGroup','teamName','investors','townName','deptName','beloneto','contents','area','enterpriseType','industryType','industryClass','useType','totalAmount','domesticAmount','foreignAmount','responsePerson','fgLeader','contactPerson','enterpriseContact','realNum','realAmount','threeAmount','threeDomestic','threeForeign','fileIds','remarks','projectYear','auditStatue','isLd'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'projectName','projectStage','projectClass','teamGroup','teamName','investors','townName','deptName','beloneto','contents','area','enterpriseType','industryType','industryClass','useType','totalAmount','domesticAmount','foreignAmount','responsePerson','fgLeader','contactPerson','enterpriseContact','realNum','realAmount','threeAmount','threeDomestic','threeForeign','fileIds','remarks','projectYear','auditStatue','isLd'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>